package info.yangguo.service;

import info.yangguo.pojo.Message00Pojo;
import info.yangguo.pojo.Message01Pojo;
import info.yangguo.pojo.Message10Pojo;
import info.yangguo.pojo.Message11Pojo;
import info.yangguo.pojo.RequestAttribute;
import info.yangguo.pojo.SMS3Pojo;
import info.yangguo.util.HexUtil;
import info.yangguo.util.Transfer;

/**
 * @author:杨果
 * @date:16/10/1 下午12:22
 *
 * Description:
 *
 * 编码Request
 */
public class EncodeRequest {
    public static byte[] encode(String MEID, String phoneNo, int serialNo, RequestAttribute requestAttribute, Object message) {
        String value;
        if (message instanceof Message00Pojo) {
            value = Transfer.encodeMessage00((Message00Pojo) message);
        } else if (message instanceof Message01Pojo) {
            value = Transfer.encodeMessage01((Message01Pojo) message);
        } else if (message instanceof Message10Pojo) {
            value = Transfer.encodeMessage10((Message10Pojo) message);
        } else if (message instanceof Message11Pojo) {
            value = Transfer.encodeMessage11((Message11Pojo) message);
        } else {
            throw new RuntimeException("消息不符合规范");
        }
        value = Transfer.encodeRequestAttribute(requestAttribute, value);
        value = Transfer.encodeSerialNo(serialNo, value);
        value = Transfer.encodePhoneNo(phoneNo, value);
        value = Transfer.encodeMEID(MEID, value);
        value = Transfer.encodeLength(value);
        value = Transfer.encodeVerify(value);
        value = Transfer.encodeTransferred(value);
        value = Transfer.encodeIdentifier(value);

        return HexUtil.decodeHex(value.toCharArray());
    }

    public static String encodeSMS(SMS3Pojo sms3Pojo) {
        return Transfer.encodeSMS3(sms3Pojo);
    }
}
